use master
go
drop database chodientu
go
create database chodientu
go
USE [chodientu]
GO
/****** Object:  Table [dbo].[TINHTHANH]    Script Date: 12/09/2012 18:01:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[TINHTHANH](
	[MAVUNG] [varchar](3) NOT NULL,
	[TENVUNG] [nvarchar](30) NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'18', N't?nh Qu?ng Ninh')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'19', N'TP H? N?i')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'20', N't?nh T?y Ninh')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'210', N't?nh Qu?ng Nam')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'211', N't?nh Kon Tum')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'22', N't?nh Kon Tum')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'23', N't?nh ?i?n Bi?n')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'240', N't?nh H? Giang')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'241', N'TP H?i Ph?ng')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'25', N't?nh V?nh Long')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'26', N't?nh H? T?y')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'27', N't?nh V?nh Ph?c')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'280', N't?nh S?n La')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'281', N't?nh H?ng Y?n')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'29', N't?nh H? T?y')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'30', N't?nh An Giang')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'31', N't?nh ??k L?k')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'320', N'TP TP. H? Ch? Minh')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'321', N't?nh V?nh Long')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'33', N't?nh Kh?nh H?a')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'34', N'TP H?i Ph?ng')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'350', N't?nh B?nh Ph??c')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'351', N't?nh H? Giang')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'36', N't?nh ?i?n Bi?n')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'37', N't?nh ?i?n Bi?n')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'38', N't?nh Ph? Th?')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'39', N't?nh B?nh D??ng')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'4', N't?nh B?nh Thu?n')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'50', N'TP ?? N?ng')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'510', N't?nh L?ng S?n')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'511', N't?nh H?a B?nh')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'52', N't?nh ??ng Nai')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'53', N't?nh S?n La')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'54', N't?nh Ti?n Giang')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'55', N't?nh Ph? Y?n')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'56', N't?nh Ninh B?nh')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'57', N't?nh ??k L?k')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'58', N't?nh L?o Cai')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'59', N't?nh ??ng Th?p')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'60', N't?nh B?nh Ph??c')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'61', N'TP TP. H? Ch? Minh')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'62', N't?nh L?m ??ng')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'63', N't?nh H?ng Y?n')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'64', N't?nh Nam ??nh')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'650', N't?nh ??ng Nai')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'651', N't?nh Tuy?n Quang')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'66', N't?nh Th?i B?nh')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'67', N't?nh Th?a Thi?n Hu?')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'68', N't?nh S?n La')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'70', N't?nh S?c Tr?ng')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'71', N'TP TP. H? Ch? Minh')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'72', N't?nh ??k N?ng')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'73', N't?nh Ninh B?nh')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'74', N't?nh L?m ??ng')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'75', N't?nh H?a B?nh')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'76', N't?nh B?c Giang')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'77', N't?nh H? Giang')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'780', N't?nh ??ng Nai')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'781', N't?nh Ph? Y?n')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'79', N't?nh H? T?y')
INSERT [dbo].[TINHTHANH] ([MAVUNG], [TENVUNG]) VALUES (N'8', N't?nh Ki?n Giang')
/****** Object:  Table [dbo].[Loaisanpham]    Script Date: 12/09/2012 18:01:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Loaisanpham](
	[Maloaisanpham] [varchar](10) NOT NULL,
	[Tenloai] [nvarchar](50) NULL,
 CONSTRAINT [PK_Loaisanpham] PRIMARY KEY CLUSTERED 
(
	[Maloaisanpham] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Giaodien]    Script Date: 12/09/2012 18:01:35 ******/
--SET ANSI_NULLS ON
--GO
--SET QUOTED_IDENTIFIER ON
--GO
--SET ANSI_PADDING ON
--GO
--CREATE TABLE [dbo].[Giaodien](
--	[Magiaodien] [varchar](10) NOT NULL,
--	[Tengiaodien] [nvarchar](50) NULL,
--	[URL] [nchar](100) NULL,
-- CONSTRAINT [PK_Giaodien] PRIMARY KEY CLUSTERED 
--(
--	[Magiaodien] ASC
--)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
--) ON [PRIMARY]
--GO
--SET ANSI_PADDING OFF
--GO
/****** Object:  Table [dbo].[Dichvu]    Script Date: 12/09/2012 18:01:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Dichvu](
	[Madichvu] [varchar](10) NOT NULL,
	[Tendichvu] [nvarchar](50) NULL,
	[Giatien] [float] NULL,
 CONSTRAINT [PK_Dichvu] PRIMARY KEY CLUSTERED 
(
	[Madichvu] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[BANGGIARAOVAT]    Script Date: 12/09/2012 18:01:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BANGGIARAOVAT](
	[LOAIRAOVAT] [int] NOT NULL,
	[TENLOAI] [nvarchar](15) NULL,
	[GIATIEN] [float] NULL,
PRIMARY KEY CLUSTERED 
(
	[LOAIRAOVAT] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Baiviet]    Script Date: 12/09/2012 18:01:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Baiviet](
	[Mabaiviet] [varchar](10) NOT NULL,
	[Noidung] [nvarchar](100) NULL,
	[Ngaydang] [datetime] NULL,
	[Theloai] [nvarchar](50) NULL,
	[Quyenriengtu] [nchar](10) NULL,
	[MaBlog] varchar(10),
 CONSTRAINT [PK_Baiviet] PRIMARY KEY CLUSTERED 
(
	[Mabaiviet] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO


SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[ACCOUNT]    Script Date: 12/09/2012 18:01:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[ACCOUNT](
	[USERNAME] [varchar](10) NOT NULL,
	[PASSWORD] [varchar](20) NULL,
	[kindOfUser] [int] NULL,
PRIMARY KEY CLUSTERED 
(
	[USERNAME] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
INSERT [dbo].[ACCOUNT] ([USERNAME], [PASSWORD], [kindOfUser]) VALUES (N'HUNG_IT', N'12345', 1)
INSERT [dbo].[ACCOUNT] ([USERNAME], [PASSWORD], [kindOfUser]) VALUES (N'yuchiychi', N'1234', 0)
/****** Object:  Table [dbo].[Phieumuasanpham]    Script Date: 12/09/2012 18:01:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Phieumuasanpham](
	[Maphieumua] [int] IDENTITY(1,1) NOT NULL,
	[Mashop] [varchar](10) NOT NULL,
	[Username] [varchar](10) NOT NULL,
	[Ngaylap] [datetime] NOT NULL,
	[Tongtien] [float] NOT NULL,
	[trangthai] [int] NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[Maphieumua] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[nguoinhan]    Script Date: 12/09/2012 18:01:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[nguoinhan](
	[manguoinhan] [int] IDENTITY(1,1) NOT NULL,
	[maphieumua] [int] NULL,
	[Hoten] [nvarchar](50) NULL,
	[dienthoai] [varchar](12) NULL,
	[email] [varchar](20) NULL,
	[tinhthanh] [nvarchar](30) NULL,
	[Diachi] [nvarchar](100) NULL,
PRIMARY KEY CLUSTERED 
(
	[manguoinhan] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Banquantri]    Script Date: 12/09/2012 18:01:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Banquantri](
	[Username] [varchar](10) NOT NULL,
	[Role] [int] NULL,
 CONSTRAINT [PK_Banquantri] PRIMARY KEY CLUSTERED 
(
	[Username] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Thanhvien]    Script Date: 12/09/2012 18:01:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Thanhvien](
	[Username] [varchar](10) NOT NULL,
	[Hoten] [nvarchar](50) NULL,
	[Ngaysinh] [date] NULL,
	[Diachi] [nvarchar](100) NULL,
	[Sotaikhoan] [nchar](10) NULL,
	[Diemtichluy] [int] NULL,
	[dienthoai] [varchar](12) NULL,
	[email] [varchar](20) NULL,
	[tinhthanh] [nvarchar](30) NULL,
 CONSTRAINT [PK_Thanhvien] PRIMARY KEY CLUSTERED 
(
	[Username] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
INSERT [dbo].[Thanhvien] ([Username], [Hoten], [Ngaysinh], [Diachi], [Sotaikhoan], [Diemtichluy], [dienthoai], [email], [tinhthanh]) VALUES (N'yuchiychi', N'Nguyen Van A', CAST(0x33170B00 AS Date), N'3/16 C1', N'1213456   ', 123, N'01267321218', N'yuchiychi@gmail.com', N't?nh H? Giang')
/****** Object:  StoredProcedure [dbo].[them_phieumua]    Script Date: 12/09/2012 18:01:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [dbo].[them_phieumua] @mashop varchar(10),@username varchar(10), @tongtien float,@tinhtrang int
as
    Declare @maphieu varchar(10)
begin
	  SET NOCOUNT ON
	  INSERT INTO Phieumuasanpham(Mashop,Username,Ngaylap,Tongtien,trangthai)
	  VALUES (@mashop,@username,GETDATE(),@tongtien,@tinhtrang)
      SELECT top 1 @maphieu = @@IDENTITY  FROM Phieumuasanpham
	  SET NOCOUNT OFF
	  select @maphieu as maphieu
end;
GO
/****** Object:  Table [dbo].[Tintuc]    Script Date: 12/09/2012 18:01:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Tintuc](
	[Matintuc] [int] IDENTITY(1,1) NOT NULL,
	[banquantri] [varchar](10) NULL,
	[Tieuderutgon] [nvarchar](100) NULL,
	[Noidung] [text] NULL,
	[Mucdo] [int] NULL,
PRIMARY KEY CLUSTERED 
(
	[Matintuc] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Tinnhan]    Script Date: 12/09/2012 18:01:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Tinnhan](
	[Matinnhan] [varchar](10) NOT NULL,
	[Username] [varchar](10) NULL,
	[Tieude] [nvarchar](100) NOT NULL,
	[Nguoigui] [varchar](10) NULL,
	[Nguoinhan] [varchar](10) NULL,
	[Ngaygoi] [datetime] NULL,
	[Noidungtinnhan] [text] NULL,
 CONSTRAINT [PK_Tinnhan] PRIMARY KEY CLUSTERED 
(
	[Matinnhan] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  StoredProcedure [dbo].[them_nguoinhan]    Script Date: 12/09/2012 18:01:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create procedure [dbo].[them_nguoinhan] @maphieumua int, @hoten nvarchar(50), @dienthoai varchar(12), @email varchar(20), @tinhthanh nvarchar(30), @diachi nvarchar(100)
as
begin
	insert into nguoinhan(maphieumua,Hoten,dienthoai,email,tinhthanh,diachi) values (@maphieumua,@hoten,@dienthoai,@email,@tinhthanh,@diachi)
end;
GO
/****** Object:  Table [dbo].[Thacmac]    Script Date: 12/09/2012 18:01:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Thacmac](
	[MaThacMac] [varchar](10) NOT NULL,
	[Banquantri] [varchar](10) NULL,
	[Username] [varchar](10) NULL,
	[Tieude] [nvarchar](100) NULL,
	[Noidung] [text] NULL,
 CONSTRAINT [PK_Thacmac] PRIMARY KEY CLUSTERED 
(
	[MaThacMac] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Blog]    Script Date: 12/09/2012 18:01:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Blog](
	[Mablog] [varchar](10) NOT NULL,
	[Username] [varchar](10) NULL,
 CONSTRAINT [PK_Blog] PRIMARY KEY CLUSTERED 
(
	[Mablog] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Raovat]    Script Date: 12/09/2012 18:01:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Raovat](
	[Maraovat] [varchar](10) NOT NULL,
	[Username] [varchar](10) NULL,
	[TieuDe] [nvarchar](100) NULL,
	[NoiDung] [text] NULL,
	[loaiRaoVat] [int] NULL,
 CONSTRAINT [PK_Raovat] PRIMARY KEY CLUSTERED 
(
	[Maraovat] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Quangcao]    Script Date: 12/09/2012 18:01:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Quangcao](
	[Maquangcao] [varchar](10) NOT NULL,
	[Username] [varchar](10) NULL,
	[Logo] [nvarchar](100) NULL,
	[Tieude] [nvarchar](100) NULL,
	[Noidung] [text] NULL,
	[Loaiquangcao] [nchar](10) NULL,
	[ThoiGian] [datetime] NULL,
	[Giatien] [float] NULL,
PRIMARY KEY CLUSTERED 
(
	[Maquangcao] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Phieumuadichvu]    Script Date: 12/09/2012 18:01:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Phieumuadichvu](
	[Maphieumua] [varchar](10) NOT NULL,
	[Username] [varchar](10) NULL,
	[Tendichvu] [nvarchar](50) NULL,
	[Ngaymua] [datetime] NULL,
	[Handung] [datetime] NULL,
 CONSTRAINT [PK_Phieumuadichvu] PRIMARY KEY CLUSTERED 
(
	[Maphieumua] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Shop]    Script Date: 12/09/2012 18:01:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Shop](
	[Mashop] [varchar](10) NOT NULL,
	[Username] [varchar](10) NULL,
	[Tenshop] [nvarchar](50) NULL,
	[Loaishop] [nvarchar](20) NULL,
	[URL] nvarchar(100),
 CONSTRAINT [PK_Shop] PRIMARY KEY CLUSTERED 
(
	[Mashop] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
INSERT [dbo].[Shop] ([Mashop], [Username], [Tenshop], [Loaishop]) VALUES (N'shop01', NULL, N'nguyen quoc nhat', NULL)
INSERT [dbo].[Shop] ([Mashop], [Username], [Tenshop], [Loaishop]) VALUES (N'shop02', NULL, N'Cao thanh h?ng', NULL)
/****** Object:  Table [dbo].[Sanpham]    Script Date: 12/09/2012 18:01:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Sanpham](
	[Masanpham] [varchar](10) NOT NULL,
	[Mashop] [varchar](10) NULL,
	[Tensanpham] [nvarchar](50) NULL,
	[loaisanpham] [varchar](10) NULL,
	[URL] [varchar](100) NULL,
	[giasanpham] [float] NULL,
	[Mota] [nvarchar](max) NULL,
 CONSTRAINT [PK_Sanpham] PRIMARY KEY CLUSTERED 
(
	[Masanpham] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
INSERT [dbo].[Sanpham] ([Masanpham], [Mashop], [Tensanpham], [loaisanpham], [URL], [giasanpham], [Mota]) VALUES (N'sp00', N'shop01', N'gi? h?ng', NULL, N'AnhSP/IMG_1275.JPG', 100000, NULL)
INSERT [dbo].[Sanpham] ([Masanpham], [Mashop], [Tensanpham], [loaisanpham], [URL], [giasanpham], [Mota]) VALUES (N'sp01', N'shop01', N'??m c?ng s? body c? t?nh m?: DA2260 - TR?NG 	', NULL, N'images/product/13.jpg', 100000, NULL)
INSERT [dbo].[Sanpham] ([Masanpham], [Mashop], [Tensanpham], [loaisanpham], [URL], [giasanpham], [Mota]) VALUES (N'sp010', N'shop01', N'??m c?ng s? body c? t?nh m?: DA2260 - TR?NG 	', NULL, N'images/product/7.gif', 100000, NULL)
INSERT [dbo].[Sanpham] ([Masanpham], [Mashop], [Tensanpham], [loaisanpham], [URL], [giasanpham], [Mota]) VALUES (N'sp011', N'shop01', N'gi? h?ng', NULL, N'images/product/8.gif', 200000, NULL)
INSERT [dbo].[Sanpham] ([Masanpham], [Mashop], [Tensanpham], [loaisanpham], [URL], [giasanpham], [Mota]) VALUES (N'sp012', N'shop02', N'Qu?n jeans n? d?y k?o x?o x? tin M?: QD140', NULL, N'images/product/9.gif', 300000, NULL)
INSERT [dbo].[Sanpham] ([Masanpham], [Mashop], [Tensanpham], [loaisanpham], [URL], [giasanpham], [Mota]) VALUES (N'sp02', N'shop01', N'gi? h?ng', NULL, N'images/product/14.jpg', 200000, NULL)
INSERT [dbo].[Sanpham] ([Masanpham], [Mashop], [Tensanpham], [loaisanpham], [URL], [giasanpham], [Mota]) VALUES (N'sp03', N'shop02', N'Qu?n jeans n? d?y k?o x?o x? tin M?: QD140', NULL, N'images/home_item.jpg', 300000, NULL)
INSERT [dbo].[Sanpham] ([Masanpham], [Mashop], [Tensanpham], [loaisanpham], [URL], [giasanpham], [Mota]) VALUES (N'sp04', N'shop01', N'??m c?ng s? body c? t?nh m?: DA2260 - TR?NG 	', NULL, N'images/product/1.jpg', 100000, NULL)
INSERT [dbo].[Sanpham] ([Masanpham], [Mashop], [Tensanpham], [loaisanpham], [URL], [giasanpham], [Mota]) VALUES (N'sp05', N'shop01', N'gi? h?ng', NULL, N'images/product/13.jpg', 200000, NULL)
INSERT [dbo].[Sanpham] ([Masanpham], [Mashop], [Tensanpham], [loaisanpham], [URL], [giasanpham], [Mota]) VALUES (N'sp06', N'shop02', N'Qu?n jeans n? d?y k?o x?o x? tin M?: QD140', NULL, N'images/product/2.jpg', 300000, NULL)
INSERT [dbo].[Sanpham] ([Masanpham], [Mashop], [Tensanpham], [loaisanpham], [URL], [giasanpham], [Mota]) VALUES (N'sp07', N'shop01', N'??m c?ng s? body c? t?nh m?: DA2260 - TR?NG 	', NULL, N'images/product/4.gif', 100000, NULL)
INSERT [dbo].[Sanpham] ([Masanpham], [Mashop], [Tensanpham], [loaisanpham], [URL], [giasanpham], [Mota]) VALUES (N'sp08', N'shop01', N'gi? h?ng', NULL, N'images/product/5.gif', 200000, NULL)
INSERT [dbo].[Sanpham] ([Masanpham], [Mashop], [Tensanpham], [loaisanpham], [URL], [giasanpham], [Mota]) VALUES (N'sp09', N'shop02', N'Qu?n jeans n? d?y k?o x?o x? tin M?: QD140', NULL, N'images/product/6.gif', 300000, NULL)
INSERT [dbo].[Sanpham] ([Masanpham], [Mashop], [Tensanpham], [loaisanpham], [URL], [giasanpham], [Mota]) VALUES (N'SP13', N'shop01', NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[Sanpham] ([Masanpham], [Mashop], [Tensanpham], [loaisanpham], [URL], [giasanpham], [Mota]) VALUES (N'SP14', N'shop01', NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[Sanpham] ([Masanpham], [Mashop], [Tensanpham], [loaisanpham], [URL], [giasanpham], [Mota]) VALUES (N'SP15', N'shop01', NULL, NULL, NULL, NULL, NULL)
/****** Object:  StoredProcedure [dbo].[sp_DSRaoVat]    Script Date: 12/09/2012 18:01:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[sp_DSRaoVat]
	@User varchar(10)
as
	if(@User <> '')
	begin
		select * from Raovat where Username like N'%' + @User + '%'
	end
	else
	begin
		select * from Raovat
	end
GO
/****** Object:  Table [dbo].[Chitietphieumuadichvu]]]    Script Date: 12/09/2012 18:01:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Chitietphieumuadichvu](
	[Madichvu] [varchar](10) NOT NULL,
	[Maphieumuadichvu] [varchar](10) NOT NULL,
 CONSTRAINT [PK_Chitietphieumuadichvu]]] PRIMARY KEY CLUSTERED 
(
	[Madichvu] ASC,
	[Maphieumuadichvu] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  StoredProcedure [dbo].[sp_DSTinNhan]    Script Date: 12/09/2012 18:01:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[sp_DSTinNhan]
	@User varchar(10)
as
	if(@User <> '')
	begin
		select * from Tinnhan where Username like N'%' + @User + '%'
	end
	else
	begin
		select * from Tinnhan
	end
GO
/****** Object:  StoredProcedure [dbo].[sp_DSSanPham]    Script Date: 12/09/2012 18:01:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[sp_DSSanPham]
	@TenSP varchar(10)
as
	if(@TenSP <> '')
	begin
		select * from Sanpham where Tensanpham like N'%' + @TenSP + '%'
	end
	else
	begin
		select * from Sanpham
	end
GO
/****** Object:  Table [dbo].[Chitietphieumuasanpham]    Script Date: 12/09/2012 18:01:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Chitietphieumuasanpham](
	[Masanpham] [varchar](10) NOT NULL,
	[Maphieumuasanpham] [int] NOT NULL,
	[soluong] [int] NOT NULL,
	[thanhtien] [float] NULL,
 CONSTRAINT [PK_Chitietphieumuasanpham] PRIMARY KEY CLUSTERED 
(
	[Masanpham] ASC,
	[Maphieumuasanpham] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO

/****** Object:  Table [dbo].[Binhluan]    Script Date: 12/09/2012 18:01:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Binhluan](
	[MaBL] [int] IDENTITY(1,1) NOT NULL,
	[MaSP] [varchar](10) NULL,
	[NoiDung] [nvarchar](max) NULL,
	[username] [varchar](10) NULL,
 CONSTRAINT [PK__Binhluan__272475AF4316F928] PRIMARY KEY CLUSTERED 
(
	[MaBL] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
SET IDENTITY_INSERT [dbo].[Binhluan] ON
INSERT [dbo].[Binhluan] ([MaBL], [MaSP], [NoiDung], [username]) VALUES (1, N'sp00', N's?n ph?m ??p', NULL)
INSERT [dbo].[Binhluan] ([MaBL], [MaSP], [NoiDung], [username]) VALUES (2, N'sp00', N'gi? h?p l?', NULL)
SET IDENTITY_INSERT [dbo].[Binhluan] OFF
/****** Object:  StoredProcedure [dbo].[sp_ThemSanPham]    Script Date: 12/09/2012 18:01:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[sp_ThemSanPham]
	@mashop varchar(10),
	@tensp nvarchar(50),
	@loaisp varchar(10),
	@url varchar(100),
	@giasp float,
	@mota nvarchar(MAX)

as
declare @masp varchar(10)
if exists (select Masanpham from Sanpham where Masanpham is not null)
	begin
		set @masp = (select max(cast(REPLACE(Masanpham,'SP','') as int)) from Sanpham)
		set @masp = @masp + 1
		
		insert into Sanpham(Masanpham, Mashop, Tensanpham, URL, giasanpham, loaisanpham, Mota)
		values(('SP' + convert(varchar(10),@masp)), @mashop, @tensp, @url, @giasp, @loaisp, @mota)
	end
else
	begin
		insert into Sanpham(Masanpham,Mashop, Tensanpham, URL, giasanpham, loaisanpham, Mota)
		values ('SP1', @mashop, @tensp, @url, @giasp, @loaisp, @mota)
	end
GO
/****** Object:  StoredProcedure [dbo].[them_chitietphieumua]    Script Date: 12/09/2012 18:01:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create procedure [dbo].[them_chitietphieumua] @masanpham varchar(10),@maphieumuasanpham int, @soluong int, @thanhtien float
as
begin
	insert into Chitietphieumuasanpham(Masanpham,Maphieumuasanpham,soluong,thanhtien)
	values (@masanpham,@maphieumuasanpham,@soluong,@thanhtien)
end ;
GO
/****** Object:  Check [CK__ACCOUNT__kindOfU__36B12243]    Script Date: 12/09/2012 18:01:35 ******/
ALTER TABLE [dbo].[ACCOUNT]  WITH CHECK ADD CHECK  (([kindOfUser]=(0) OR [kindOfUser]=(1)))
GO
/****** Object:  ForeignKey [FK_BANQUANTRI_ACCOUNT]    Script Date: 12/09/2012 18:01:35 ******/
ALTER TABLE [dbo].[Banquantri]  WITH CHECK ADD  CONSTRAINT [FK_BANQUANTRI_ACCOUNT] FOREIGN KEY([Username])
REFERENCES [dbo].[ACCOUNT] ([USERNAME])
GO
ALTER TABLE [dbo].[Banquantri] CHECK CONSTRAINT [FK_BANQUANTRI_ACCOUNT]
GO
/****** Object:  ForeignKey [FK__Binhluan__MaSP__44FF419A]    Script Date: 12/09/2012 18:01:35 ******/
ALTER TABLE [dbo].[Binhluan]  WITH CHECK ADD  CONSTRAINT [FK__Binhluan__MaSP__44FF419A] FOREIGN KEY([MaSP])
REFERENCES [dbo].[Sanpham] ([Masanpham])
GO
ALTER TABLE [dbo].[Binhluan] CHECK CONSTRAINT [FK__Binhluan__MaSP__44FF419A]
GO
/****** Object:  ForeignKey [fk_binhluan_thanhvien]    Script Date: 12/09/2012 18:01:35 ******/
ALTER TABLE [dbo].[Binhluan]  WITH CHECK ADD  CONSTRAINT [fk_binhluan_thanhvien] FOREIGN KEY([username])
REFERENCES [dbo].[Thanhvien] ([Username])
GO
ALTER TABLE [dbo].[Binhluan] CHECK CONSTRAINT [fk_binhluan_thanhvien]
GO
/****** Object:  ForeignKey [FK_Blog_Baiviet]    Script Date: 12/09/2012 18:01:35 ******/
/****** Object:  ForeignKey [FK_Blog_Thanhvien]    Script Date: 12/09/2012 18:01:35 ******/
ALTER TABLE [dbo].[Blog]  WITH CHECK ADD  CONSTRAINT [FK_Blog_Thanhvien] FOREIGN KEY([Username])
REFERENCES [dbo].[Thanhvien] ([Username])
GO
ALTER TABLE [dbo].[Blog] CHECK CONSTRAINT [FK_Blog_Thanhvien]
GO
/****** Object:  ForeignKey [FK_Chitietphieumuadichvu]]_Dichvu]    Script Date: 12/09/2012 18:01:35 ******/
ALTER TABLE [dbo].[Chitietphieumuadichvu]  WITH CHECK ADD  CONSTRAINT [FK_Chitietphieumuadichvu_Dichvu] FOREIGN KEY([Madichvu])
REFERENCES [dbo].[Dichvu] ([Madichvu])
GO
ALTER TABLE [dbo].[Chitietphieumuadichvu] CHECK CONSTRAINT [FK_Chitietphieumuadichvu_Dichvu]
GO
/****** Object:  ForeignKey [FK_Chitietphieumuadichvu]]_Phieumuadichvu]    Script Date: 12/09/2012 18:01:35 ******/
ALTER TABLE [dbo].[Chitietphieumuadichvu]  WITH CHECK ADD  CONSTRAINT [FK_Chitietphieumuadichvu_Phieumuadichvu] FOREIGN KEY([Maphieumuadichvu])
REFERENCES [dbo].[Phieumuadichvu] ([Maphieumua])
GO
ALTER TABLE [dbo].[Chitietphieumuadichvu] CHECK CONSTRAINT [FK_Chitietphieumuadichvu_Phieumuadichvu]
GO
/****** Object:  ForeignKey [FK_Chitietphieumuasanpham_Phieumuasanpham]    Script Date: 12/09/2012 18:01:35 ******/
ALTER TABLE [dbo].[Chitietphieumuasanpham]  WITH CHECK ADD  CONSTRAINT [FK_Chitietphieumuasanpham_Phieumuasanpham] FOREIGN KEY([Maphieumuasanpham])
REFERENCES [dbo].[Phieumuasanpham] ([Maphieumua])
GO
ALTER TABLE [dbo].[Chitietphieumuasanpham] CHECK CONSTRAINT [FK_Chitietphieumuasanpham_Phieumuasanpham]
GO

/****** Object:  ForeignKey [FK_Chitietphieumuasanpham_Sanpham]    Script Date: 12/09/2012 18:01:35 ******/
ALTER TABLE [dbo].[Chitietphieumuasanpham]  WITH CHECK ADD  CONSTRAINT [FK_Chitietphieumuasanpham_Sanpham] FOREIGN KEY([Masanpham])
REFERENCES [dbo].[Sanpham] ([Masanpham])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Chitietphieumuasanpham] CHECK CONSTRAINT [FK_Chitietphieumuasanpham_Sanpham]
GO
/****** Object:  ForeignKey [FK_phieumua_nguoinhan]    Script Date: 12/09/2012 18:01:35 ******/
ALTER TABLE [dbo].[nguoinhan]  WITH CHECK ADD  CONSTRAINT [FK_phieumua_nguoinhan] FOREIGN KEY([maphieumua])
REFERENCES [dbo].[Phieumuasanpham] ([Maphieumua])
GO
ALTER TABLE [dbo].[nguoinhan] CHECK CONSTRAINT [FK_phieumua_nguoinhan]
GO
/****** Object:  ForeignKey [FK_Phieumuadichvu_Thanhvien]    Script Date: 12/09/2012 18:01:35 ******/
ALTER TABLE [dbo].[Phieumuadichvu]  WITH CHECK ADD  CONSTRAINT [FK_Phieumuadichvu_Thanhvien] FOREIGN KEY([Username])
REFERENCES [dbo].[Thanhvien] ([Username])
GO
ALTER TABLE [dbo].[Phieumuadichvu] CHECK CONSTRAINT [FK_Phieumuadichvu_Thanhvien]
GO
/****** Object:  ForeignKey [FK_Quangcao_Thanhvien]    Script Date: 12/09/2012 18:01:35 ******/
ALTER TABLE [dbo].[Quangcao]  WITH CHECK ADD  CONSTRAINT [FK_Quangcao_Thanhvien] FOREIGN KEY([Username])
REFERENCES [dbo].[Thanhvien] ([Username])
GO
ALTER TABLE [dbo].[Quangcao] CHECK CONSTRAINT [FK_Quangcao_Thanhvien]
GO
/****** Object:  ForeignKey [FK_RAOVAT_BANGGIARAOVAT]    Script Date: 12/09/2012 18:01:35 ******/
ALTER TABLE [dbo].[Raovat]  WITH CHECK ADD  CONSTRAINT [FK_RAOVAT_BANGGIARAOVAT] FOREIGN KEY([loaiRaoVat])
REFERENCES [dbo].[BANGGIARAOVAT] ([LOAIRAOVAT])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Raovat] CHECK CONSTRAINT [FK_RAOVAT_BANGGIARAOVAT]
GO
/****** Object:  ForeignKey [FK_Raovat_Thanhvien]    Script Date: 12/09/2012 18:01:35 ******/
ALTER TABLE [dbo].[Raovat]  WITH CHECK ADD  CONSTRAINT [FK_Raovat_Thanhvien] FOREIGN KEY([Username])
REFERENCES [dbo].[Thanhvien] ([Username])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Raovat] CHECK CONSTRAINT [FK_Raovat_Thanhvien]
GO
/****** Object:  ForeignKey [FK_Sanpham_Loaisanpham]    Script Date: 12/09/2012 18:01:35 ******/
ALTER TABLE [dbo].[Sanpham]  WITH CHECK ADD  CONSTRAINT [FK_Sanpham_Loaisanpham] FOREIGN KEY([loaisanpham])
REFERENCES [dbo].[Loaisanpham] ([Maloaisanpham])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Sanpham] CHECK CONSTRAINT [FK_Sanpham_Loaisanpham]
GO
/****** Object:  ForeignKey [FK_Sanpham_Shop]    Script Date: 12/09/2012 18:01:35 ******/
ALTER TABLE [dbo].[Sanpham]  WITH CHECK ADD  CONSTRAINT [FK_Sanpham_Shop] FOREIGN KEY([Mashop])
REFERENCES [dbo].[Shop] ([Mashop])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Sanpham] CHECK CONSTRAINT [FK_Sanpham_Shop]
GO
/****** Object:  ForeignKey [FK_Shop_Giaodien]    Script Date: 12/09/2012 18:01:35 ******/
GO
/****** Object:  ForeignKey [FK_Shop_Thanhvien]    Script Date: 12/09/2012 18:01:35 ******/
ALTER TABLE [dbo].[Shop]  WITH CHECK ADD  CONSTRAINT [FK_Shop_Thanhvien] FOREIGN KEY([Username])
REFERENCES [dbo].[Thanhvien] ([Username])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Shop] CHECK CONSTRAINT [FK_Shop_Thanhvien]
GO
/****** Object:  ForeignKey [FK_Thacmac_Banquantri]    Script Date: 12/09/2012 18:01:35 ******/
ALTER TABLE [dbo].[Thacmac]  WITH CHECK ADD  CONSTRAINT [FK_Thacmac_Banquantri] FOREIGN KEY([Banquantri])
REFERENCES [dbo].[Banquantri] ([Username])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Thacmac] CHECK CONSTRAINT [FK_Thacmac_Banquantri]
GO
/****** Object:  ForeignKey [FK_Thacmac_Thanhvien]    Script Date: 12/09/2012 18:01:35 ******/
ALTER TABLE [dbo].[Thacmac]  WITH CHECK ADD  CONSTRAINT [FK_Thacmac_Thanhvien] FOREIGN KEY([Username])
REFERENCES [dbo].[Thanhvien] ([Username])
GO
ALTER TABLE [dbo].[Thacmac] CHECK CONSTRAINT [FK_Thacmac_Thanhvien]
GO
/****** Object:  ForeignKey [fk_thanhvien_account]    Script Date: 12/09/2012 18:01:35 ******/
ALTER TABLE [dbo].[Thanhvien]  WITH CHECK ADD  CONSTRAINT [fk_thanhvien_account] FOREIGN KEY([Username])
REFERENCES [dbo].[ACCOUNT] ([USERNAME])
GO
ALTER TABLE [dbo].[Thanhvien] CHECK CONSTRAINT [fk_thanhvien_account]
GO
/****** Object:  ForeignKey [FK_Tinnhan_Thanhvien]    Script Date: 12/09/2012 18:01:35 ******/
ALTER TABLE [dbo].[Tinnhan]  WITH CHECK ADD  CONSTRAINT [FK_Tinnhan_Thanhvien] FOREIGN KEY([Username])
REFERENCES [dbo].[Thanhvien] ([Username])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Tinnhan] CHECK CONSTRAINT [FK_Tinnhan_Thanhvien]
GO
/****** Object:  ForeignKey [FK_Tintuc_Banquantri]    Script Date: 12/09/2012 18:01:35 ******/
ALTER TABLE [dbo].[Tintuc]  WITH CHECK ADD  CONSTRAINT [FK_Tintuc_Banquantri] FOREIGN KEY([banquantri])
REFERENCES [dbo].[Banquantri] ([Username])
GO
ALTER TABLE [dbo].[Tintuc] CHECK CONSTRAINT [FK_Tintuc_Banquantri]
GO
alter table BaiViet
add constraint fk_baiviet_blog
foreign key(MaBlog)
references Blog(MaBlog)
go